package com.itheima.common;

import com.itheima.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
        log.error("全局异常处理器捕获到异常：", e);
        return Result.error("很抱歉, 服务器开小车了");
    }

    @ExceptionHandler(BizException.class)
    public Result handlerException(BizException e) {
        log.error("捕获到异常：", e);
        return Result.error(e.getMessage());
    }

}
